<?php

function create_uuid($prefix = "dy_") {    //可以指定前缀
    $str = md5(uniqid(mt_rand(), true));
    $uuid = substr($str, 0, 8) . '-';
    $uuid .= substr($str, 8, 4) . '-';
    $uuid .= substr($str, 12, 4) . '-';
    $uuid .= substr($str, 16, 4) . '-';
    $uuid .= substr($str, 20, 12);
    return $prefix . $uuid;
}

function create_dir($path) {
    if (!file_exists($path)) {
        create_dir(dirname($path));
        mkdir($path, 0777);
    }
}

function verify_token($token) {
    $User = new \Common\Model\UserModel();
    $user = $User->where("token = '" . $token . "'")->find();
    $result['code'] = "200";
    if ($user == null) {
        $result['code'] = "407"; //无效的token
        echo json_encode($result, JSON_PRETTY_PRINT);
        die();
    }
    $user['password'] = "";
//    $result['result'] = $user;
//    echo json_encode($result, JSON_PRETTY_PRINT);
    return $user;
}

function verify_app_key($app_key) {
    if (APP_KEY != $app_key) {
        $result['code'] = "406"; //非法的App_key
//        echo json_encode($result, JSON_PRETTY_PRINT);
//        die();
    }
}

/*
      function verify_app_key($app_key){
      $user = new \Common\Model\UserModel();
      show_bug($user);
      }
     */    